<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="com.jframe.sys.utils.StringUtil" %>
<%@ page import="com.jframe.sso.model.CurUser" %>
<%
String contextPath = request.getContextPath();
CurUser user = (CurUser)session.getAttribute("curUser");
int id = StringUtil.parseInt(request.getParameter("id"));
int groupId = StringUtil.parseInt(request.getParameter("groupId"));
String type = StringUtil.null2Space(request.getParameter("type"));
String userNo = user.getUserNo();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/inc/editInc.jsp" />
<script type="text/javascript">
$(function(){
	var action = 'userAction';
	$.ajax({
		url: action+'.do?method=getObjById',
		type: 'post',
		data:{id:$('#id').val()},
		dataType:'json',
	    success: function(data){
	    	$('#data').form('load',data);
	    	$("#skintemp").val(data.skin);
	    }
	});
	
	var saveForm = function(){
		<%
		    if(type.equals("add")){
		%>
		var pwd = $("#pwd").val();
		var pwd1 = $("#pwd1").val();
		if(pwd!=pwd1){
			alertError("两次输入的密码不相等！");
			return;
		}
		<% 
		    }
		%>
		var validate = $('#data').form('validate');
		if(validate){
			var skin = $("#skintemp").val();
		$.ajax({
			url:action+".do?method=save",
			data:{obj:$("#data").form2json(),type:'<%=type%>'},
			dataType:'json',
			type:'post',
			success:function(data){
				if(data.result==true){
					var obj = data.obj; 
					$('#data').form('load',obj);
					if(skin!=obj.skin&&obj.userNo=='<%=userNo%>'){
						alertInfo('保存成功，您修改了皮肤，刷新后生效。');
					}else{
						alertInfo('保存成功！');
						parent.$('#grid').datagrid('reload');
					}
				}
				else{
					alertError('保存失败！');
				}
			}
		});
		}else{
			return validate;
		}
	};
	$('#saveBtn').click(saveForm);
});
</script>
</head>
<body>
    <form id="data" method="post">
    	<input type="hidden" id="id" name="id" value="<%=id%>"/>
    	<input type="hidden" id="groupId" name="groupId" value="<%=groupId%>"/>
    	<input type="hidden" id="skintemp" name="skintemp" />
	    <table width="100%" class="tableForm">
	   		<tr align="center">
		    	<th colspan="4">		    
		    	<span>用户管理</span>    	
			    </th>
		    </tr>
		    <tr>
		    	<td width="15%" align="right">
		    		账号：
		    	</td>
		     <%
		    if(type.equals("add")){
		    	%>
			    <td width="35%" align="left">
			    	<input type="text" id="userNo" name="userNo" required="true" style="width:150px;" class="easyui-validatebox"/>
			    </td>
			   	<% 
		    }else{
		    	%>
		    	 <td width="35%" align="left">
			    	<input type="text" id="userNo" name="userNo" required="true" style="width:150px;" class="easyui-validatebox" readonly="readonly"/>
			    </td>		    	
		    	<%		    	
		    }		     
		     %>
			    <td width="15%" align="right">
		    		用户名：
		    	</td>
				<td width="35%" align="left">
					<input type="text" id="userName" name="userName" required="true" style="width:150px;" class="easyui-validatebox"/>
				</td>
		    </tr>
		    <%
		    if(type.equals("add")){
		    	%>
		    	<tr>
		    	<td width="15%" align="right">
		    		密码：
		    	</td>
			    <td width="35%" align="left">
			    	<input type="password" id="pwd" name="pwd" required="true" style="width:150px;" class="easyui-validatebox"/>
			    </td>
			    <td width="15%" align="right">
		    		确认密码：
		    	</td>
				<td width="35%" align="left">
					<input type="password" id="pwd1" name="pwd1" required="true" style="width:150px;" class="easyui-validatebox"/>
				</td>
		    </tr>		    	
		    	<% 
		    }
		    %>		    
			<tr>			
				<td align="right">
		    		角色：
		    	</td>
				<td>
					<select id="roleId" name="roleId"  required="true" class="easyui-combotree" style="width:155px;" url="<%=request.getContextPath()%>/roleAction.do?method=getUpRoles&groupId=<%=groupId%>"></select>
				</td>
				<td align="right">
		    		皮肤：
		    	</td>
				<td>
					<select id="skin" name="skin"  class="easyui-combobox" valueField="id" textField="text" style="width:155px;" required="true" url="<%=request.getContextPath()%>/userAction.do?method=getCombobox&key=dm_sys_themes"></select>
				</td>
			</tr>
			<tr>						
				<td align="right">
		    		联系方式：
		    	</td>
				<td>
					<input type="text" id="tel" name="tel"  style="width:150px;" class="easyui-validatebox"/>
				</td>
				<td align="right">
		    		email：
		    	</td>
				<td>
					<input type="text" id="email" name="email"  style="width:150px;" class="easyui-validatebox"/>
				</td>
			</tr>
			<tr>						
				<td align="right">
		    		成员：
		    	</td>
				<td>
					<input type="text" id="memberId" name="memberId"  style="width:150px;" class="easyui-validatebox"/>
				</td>
				<td align="right">
		    		有效否：
		    	</td>
				<td>
					<select id="active" name="active"  required="true" class="easyui-combobox" style="width:155px;">
						<option value="1">有效</option>
						<option value="0">无效</option>
					</select>
				</td>
			</tr>
			<tr align="center">
				<td colspan="4">
					<a id='saveBtn' class="easyui-linkbutton" plain="true" iconCls="icon-save">保存</a>
				</td>
			</tr>
		</table>
    </form>
</body>
</html>